package com.comcast.core.eeg.types;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class BusinessEvent implements java.io.Serializable {

	private static final long serialVersionUID = -8121947631362320915L;

	private Map<EventAspect, Serializable> aspects = new HashMap<EventAspect, Serializable>();

    private Map<String, Serializable> headers = new HashMap<String, Serializable>();

    public BusinessEvent() {}

    public BusinessEvent(java.lang.String eventName, EventDetails details) {
        this.eventName = eventName;
        this.details = details;
    }

    public Map<EventAspect, Serializable> getAspectValues() {
        return aspects;
    }

    public Map<NotificationHeader, Serializable> getNotificationHeaderValues() {
        Map<NotificationHeader, Serializable> result = new HashMap<NotificationHeader, Serializable>(
                headers.size());
        Set<Entry<String, Serializable>> entries = headers.entrySet();
        for (Entry<String, Serializable> entry : entries) {
            result.put(NotificationHeader.fromValue(entry.getKey()), entry
                    .getValue());
        }
        return result;
    }

    public boolean addAspectValue(EventAspect aspect, Serializable value) {
        if (aspect == null || value == null) {
            return false;
        }

        // check supported data type
        if (value instanceof Boolean || value instanceof Byte
                || value instanceof Short || value instanceof Integer
                || value instanceof Long || value instanceof Float
                || value instanceof Double || value instanceof String) {
            aspects.put(aspect, value);
            return true;
        } else {
            return false;
        }
    }

    public boolean addNotificationHeaderValue(NotificationHeader header, Serializable value) {
        if (header == null || value == null) {
            return false;
        }

        // check supported data type
        if (value instanceof Boolean || value instanceof Byte
                || value instanceof Short || value instanceof Integer
                || value instanceof Long || value instanceof Float
                || value instanceof Double || value instanceof String) {
            headers.put(header.getValue(), value);
            return true;
        } else {
            return false;
        }
    }

    private java.lang.String eventName;

    public java.lang.String getEventName() {
        return this.eventName;
    }

    public void setEventName(java.lang.String eventName) {
        this.eventName = eventName;
    }

    private EventDetails details;

    public EventDetails getDetails() {
        return this.details;
    }

    public void setDetails(EventDetails details) {
        this.details = details;
    }

	@Override
	public String toString() {
		return "BusinessEvent [aspects=" + aspects + ", headers=" + headers
				+ ", eventName=" + eventName + ", details=" + details + "]";
	}
    

}